#include <iostream>
#include <initializer_list>
#include <list>
#include <map>

using namespace std;

struct Act
{
	size_t _id = 0;
	size_t _begTime = 0;
	size_t _endTime = 0;
};


void solve(list<Act*>& outList, initializer_list<Act*> il)
{
	if (!il.size())
		return;

	multimap<size_t, Act*> actMap;
	for (auto pA : il)
		actMap.insert(make_pair(pA->_endTime, pA));

	for (auto pr : actMap)
	{
		if (outList.empty() || outList.back()->_endTime <= pr.second->_begTime)
			outList.push_back(pr.second);
	}
}

int main()
{
	Act a1{ 1, 1, 4 };
	Act a2{ 2, 3, 5 };
	Act a3{ 3, 0, 6 };
	Act a4{ 4, 5, 7 };
	Act a5{ 5, 3, 9 };
	Act a6{ 6, 5, 9 };
	Act a7{ 7, 6, 10 };
	Act a8{ 8, 8, 11 };
	Act a9{ 9, 8, 12 };
	Act a10{ 10, 2, 14 };
	Act a11{ 11, 12, 16 };
	list<Act*> outList;
	solve(outList, { &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10, &a11 });
	bool first = true;
	for (auto pA : outList)
	{
		if (first)
			first = false;
		else
			cout << ",";

		cout << "a" << pA->_id << ":" << pA->_begTime << "-" << pA->_endTime;
	}
	cout << endl;

	return 0;
}